/**
 * @param {string} word1
 * @param {string} word2
 * @return {string}
 */
export var mergeAlternately = function (word1, word2) {
  let ans = ''
  const n = Math.max(word1.length, word2.length)
  let i = 0
  while (i < n) {
    ans += (word1[i] || '') + (word2[i] || '')
    i++
  }
  return ans
}

/**
 * 按短的那个字符长度截断长字符，只枚举短的长度次数即可，然后拼上长的余下部分
 * @param {string} word1
 * @param {string} word2
 * @return {string}
 */
export var mergeAlternately2 = function (word1, word2) {
  let min = 0
  let end = ''
  if (word1.length > word2.length) {
    min = word2.length
    end = word1.slice(min)
  } else if (word1.length < word2.length) {
    min = word1.length
    end = word2.slice(min)
  } else {
    min = word1.length
  }
  let ans = ''
  for (let i = 0; i < min; i++) {
    ans += word1[i] + word2[i]
  }
  return ans + end
}
